import { getFrockList } from '@/api/sop/mesCoEsopInfo'
import { uniqueKey } from '@/utils/judge'

export const frockDialog = {
  data () {
    return {
      frockDialogVisible: false, //表格弹框隐藏显示
      getFrockList, // 获取弹框数据接口
      frockHasFooter: true, // 是否需要底部按钮默认true
      frockSearchDialog: {
        inline: true,
        span: 24,
        formDesc: {
          frockCode: {
            type: 'input',
            layout: 12,
            label: $i18n.t('mesCoEsopInfo.frockCode')
          },
          frockName: {
            type: 'input',
            layout: 12,
            label: $i18n.t('mesCoEsopInfo.frockName')
          }
        }
      },
      frockDialogColumn: [
        {
          type: 'selection'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60
        },
        {
          prop: 'frockCode',
          label: $i18n.t('mesCoEsopInfo.frockCode'),
          showOverflowTooltip: true
        },
        {
          prop: 'frockName',
          label: $i18n.t('mesCoEsopInfo.frockName'),
          showOverflowTooltip: true
        }
      ]
    }
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    setSelectFrock (data) {
      let list = [
        ...(this.formDataDialog?.sopFrockList ?? []),
        ...data.map((ite) => {
          return {
            frockCode: ite.frockCode,
            frockName: ite.frockName,
            frockid: ite.id
          }
        })
      ]
      // 筛选重复值,插入
      this.$set(this.formDataDialog, 'sopFrockList', uniqueKey(list, 'frockid'))
    }
  }
}
